function $(selector){
    return document.querySelector(selector);
}
/**
 * 图书分类
 */
var bookTypes = JSON.parse(localStorage.getItem('bookTypes'));
for(var key in bookTypes){
   var html = template("sidebar-menu",bookTypes[key]);
   $('.main .sidebar ul.menu').innerHTML += html;
}
/**
 * 轮播图
 */
var slide= JSON.parse(localStorage.getItem('slides'));
for(var s of slide){
    var div = document.createElement('div');
    div.className = 'swiper-slide';
    var img = document.createElement('img');
    img.src = './imgs/slides/'+s;
    div.appendChild(img);
    $('.swiper-wrapper').appendChild(div);
}

var mySwiper = new Swiper('.swiper-container',{
    autoplay:{
        delay: 1000,//1秒切换一次
        disableOnInteraction: false,
    },
    loop:true, // 循环播放
    pagination: {
        el: '.swiper-pagination', 
        clickable :true,
    },
    navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
    },
    effect : 'fade',
    
});
// //鼠标滑过pagination控制swiper切换
// for(i=0;i<mySwiper.pagination.bullets.length;i++){
//     mySwiper.pagination.bullets[i].onmouseover=function(){
//       this.click();
//     };
//   }
/**
 * 猜你喜欢
 */
var guessLike= JSON.parse(localStorage.getItem('guessLikes'));
// console.log(guessLikes);
// var img = document.createElement('img');
// img.src = './imgs/guessLikes/'+guessLike[0].img;
// $('.tab-panel .intro .left').appendChild(img); 
// for(var g in guessLike){
    // var html = template("tab-panel",guessLike[0]);
    // // console.log(html);
    // $('.tabs-content ').innerHTML += html;
// } 
// for(var g = 1;g<guessLike.length-1;g++){
//     var html = template("tab-panel",guessLike[g]);
//     // console.log(html);
//     $('.tabs-content .tab-panel .list').innerHTML += html;
// }   
/**
 * 图书畅销榜
 */
var bestSelling= JSON.parse(localStorage.getItem('bestSelling'));
for(var b=1;b<bestSelling.length+1;b++){
    var li = document.createElement('li');
    var a = document.createElement('a');
    if(b<10){
        a.innerHTML = '0'+b+'.'+bestSelling[b-1];
    }else{
        a.innerHTML = b+'.'+bestSelling[b-1];
    }
    
    li.appendChild(a);
    $('.bestSelling .list').appendChild(li);
}